<?php
namespace Purse\Model;
use Think\Model;
class PurseModel extends Model {
	protected $connection = 'DB_BASE_DSN';
	protected $tableName = 'qyx_purse'; 
	
	
	public function savePurse($data){
		$map['custid'] = $data['custid'];
		$ret = $this->where($map)->find();
		if(!empty($ret)){
			//$data['amount'] = $ret['amount'] + $data['amount'];
			$data['updatetime'] = date("Y-m-d H:i:s");
			
			//if(bccomp($data['amount'], '0.00' , 2) < 0) return false;
			
			$result = $this->where($map)->save($data);
		}else{
			$result = $this->add($data);
		}
		
		//return $data['amount'];
		return $result;
	}
	
	
	public function getPurse($data){
		$map['custid'] = $data['custid'];
		$result = $this->where($map)->find();
		if(empty($result)) $result['amount'] = "0.00";
		return $result;
	}
}


